package com.goldgov.statistics.indexchar.web;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.goldgov.conference.service.ConferenceStat;
import com.goldgov.conference.service.ConferenceStatQuery;
import com.goldgov.distancelearning.service.Distancelearning;
import com.goldgov.distancelearning.service.DistancelearningQuery;
import com.goldgov.distancelearning.service.DistancelearningService;
import com.goldgov.kcloud.core.json.JsonQueryObject;
import com.goldgov.utils.DateUtil;
import com.goldgov.utils.PropertyUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequestMapping("/workbench/statistics/distanceLearningchart")
@Api("远程教育统计首页接口")
public class DistanceLearningCharController {
	@Autowired
	private DistancelearningService distancelearningService;
	
	@GetMapping("/countDistancelearningAttachPercentage")
	@ApiOperation(value = "会议材料分布百分比", notes = "会议材料分布百分比")
	@ApiImplicitParams({@ApiImplicitParam(name = "searchBeginDate", value = "开始时间", paramType = "query"),
		@ApiImplicitParam(name = "searchEndDate", value = "结束时间", paramType = "query"),
		@ApiImplicitParam(name = "searchOrganizationID", value = "机构id", paramType = "query")})
	public JsonQueryObject<Distancelearning> countDistancelearningAttachPercentage(@ApiIgnore DistancelearningQuery query,
			HttpServletRequest request, Model model) {
		List<Distancelearning> list=distancelearningService.countDistancelearningAttachPercentage(query);
		query.setResultList(list);
		return new JsonQueryObject<>(query);
	}
	
	@GetMapping("/countDistancelearningPercentageRegion")
	@ApiOperation(value = "各地区会议指标完成度", notes = "地域分布")
	@ApiImplicitParams({ @ApiImplicitParam(name = "searchType", value = "会议类型", paramType = "query"),
			@ApiImplicitParam(name = "searchBeginDate", value = "开始时间", paramType = "query"),
			@ApiImplicitParam(name = "searchEndDate", value = "结束时间", paramType = "query"),
			@ApiImplicitParam(name = "searchOrganizationID", value = "机构id", paramType = "query"),
			@ApiImplicitParam(name = "serarchNextNum", value = "子机构数", paramType = "query"),
			@ApiImplicitParam(name = "searchOrderType", value = "排序类型", paramType = "query"),
			@ApiImplicitParam(name = "searchOrganizationType", value = "机构类型", paramType = "query")})
	public JsonQueryObject<Distancelearning> countDistancelearningPercentageRegion(@ApiIgnore DistancelearningQuery query,
			HttpServletRequest request, Model model) throws Exception {
		if (!PropertyUtil.objectNotEmpty(query.getSearchBeginDate())) {
			//取得当前年
			int year=DateUtil.getYear(new Date());
			query.setSearchBeginDate(year+"-01");
			query.setSearchEndDate(year+"-12");
		}
		List<Distancelearning> list=distancelearningService.countDistancelearningPercentageRegion(query);
		query.setResultList(list);
		return new JsonQueryObject<>(query);
	}
	
	@GetMapping("/countDistancelearningPercentageAvg")
	@ApiOperation(value = "会议指标完成度", notes = "类型会议指标完成度")
	@ApiImplicitParams({ @ApiImplicitParam(name = "searchType", value = "会议类型", paramType = "query"),
			@ApiImplicitParam(name = "searchBeginDate", value = "开始时间", paramType = "query"),
			@ApiImplicitParam(name = "searchEndDate", value = "结束时间", paramType = "query"),
			@ApiImplicitParam(name = "searchOrganizationID", value = "机构id", paramType = "query"),
			@ApiImplicitParam(name = "serarchNextNum", value = "子机构数", paramType = "query"),
			@ApiImplicitParam(name = "searchOrderType", value = "排序类型", paramType = "query"),
			@ApiImplicitParam(name = "searchOrganizationType", value = "机构类型", paramType = "query")})
	public JsonQueryObject<Distancelearning> countDistancelearningPercentageAvg(@ApiIgnore DistancelearningQuery query,
			HttpServletRequest request, Model model) throws Exception {
		if (!PropertyUtil.objectNotEmpty(query.getSearchBeginDate())) {
			//取得当前年
			int year=DateUtil.getYear(new Date());
			query.setSearchBeginDate(year+"-01");
			query.setSearchEndDate(year+"-12");
		}
		List<Distancelearning> list=distancelearningService.countDistancelearningPercentageAvg(query);
		query.setResultList(list);
		return new JsonQueryObject<>(query);
	}
	
	@GetMapping("/countDistancelearningFinishOrg")
	@ApiOperation(value = "子级已完成指标的机构", notes = "已完成指标的机构")
	@ApiImplicitParams({ @ApiImplicitParam(name = "searchType", value = "会议类型", paramType = "query"),
			@ApiImplicitParam(name = "searchBeginDate", value = "开始时间", paramType = "query"),
			@ApiImplicitParam(name = "searchEndDate", value = "结束时间", paramType = "query"),
			@ApiImplicitParam(name = "searchOrganizationID", value = "机构id", paramType = "query"),
			@ApiImplicitParam(name = "serarchNextNum", value = "子机构数", paramType = "query"),
			@ApiImplicitParam(name = "searchOrganizationType", value = "机构类型", paramType = "query")})
	public JsonQueryObject<Distancelearning> countDistancelearningFinishOrg(@ApiIgnore DistancelearningQuery query,
			HttpServletRequest request, Model model) throws Exception {
		if (!PropertyUtil.objectNotEmpty(query.getSearchBeginDate())) {
			//取得当前年
			int year=DateUtil.getYear(new Date());
			query.setSearchBeginDate(year+"-01");
			query.setSearchEndDate(year+"-12");
		}
		List<Distancelearning> list=distancelearningService.countDistancelearningFinishOrg(query);
		query.setResultList(list);
		return new JsonQueryObject<>(query);
	}
	
	@GetMapping("/countDistancelearningPercentageBynum")
	@ApiOperation(value = "会议完成数量对比", notes = "会议完成数量对比")
	@ApiImplicitParams({ @ApiImplicitParam(name = "searchType", value = "会议类型", paramType = "query"),
			@ApiImplicitParam(name = "searchBeginDate", value = "开始时间", paramType = "query"),
			@ApiImplicitParam(name = "searchEndDate", value = "结束时间", paramType = "query"),
			@ApiImplicitParam(name = "searchOrganizationID", value = "机构id", paramType = "query")})
	public JsonQueryObject<ConferenceStat> countDistancelearningPercentageBynum(@ApiIgnore ConferenceStatQuery query,
			HttpServletRequest request, Model model) throws Exception {
		if (!PropertyUtil.objectNotEmpty(query.getSearchBeginDate())) {
			//取得当前年
			int year=DateUtil.getYear(new Date());
			query.setSearchBeginDate(year+"-01");
			query.setSearchEndDate(year+"-12");
		}
		query.setSearchType(String.valueOf(5));//远程教育
		List<ConferenceStat> list=distancelearningService.countDistancelearningPercentageBynum(query);
		query.setResultList(list);
		return new JsonQueryObject<>(query);
	}
}
